<template>
  <div class="wrapper">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icons" v-for="item of page" :key="item.id">
          <div class="icons-img">
            <img :src="'/static/icons/' + item.url" class="icons-img-content" alt="">
          </div>
          <p class="icons-title">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'TravelIcons',
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  props: {
    iconsList: {
      type: Array
    }
  },
  computed: {
    pages () {
      let pages = []
      this.iconsList.forEach((item, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped lang="stylus">
  @import '~css/varibles.styl'
  @import '~css/mixins.styl'
  .wrapper >>> .swiper-container
    width: 100%
    height: 0
    overflow: hidden
    padding-bottom: 50%
  .wrapper
    touch-action: none//这一行是为了解决滑动浏览器给出警告的问题
    margin-top: .1rem
    .icons
      width: 25%
      height: 0
      overflow: hidden
      padding-bottom: 25%
      overflow: hidden
      position: relative
      float: left
      .icons-img
        position: absolute
        top: 0
        right: 0
        bottom: .44rem
        left: 0
        text-align: center
        box-sizing: border-box
        padding: .1rem
        .icons-img-content
          height: 100%
      .icons-title
        position: absolute
        right: 0
        bottom: 0
        left: 0
        height: .44rem
        line-height: .44rem
        color: $darkTextColor
        text-align: center
        ellipsis()

</style>
